package com.fjeld.client.gui.screens.node;

import com.fjeld.middleware.activemq.HeartbeatCellRenderer;
import com.fjeld.middleware.activemq.HeartbeatListener;
import com.fjeld.middleware.activemq.HeartbeatTableModel;
import com.fjeld.swingx.JTransparentPanel;
import com.fjeld.client.gui.util.factories.LabelFactory;
import com.fjeld.swingx.JTransparentScrollPane;
import com.fjeld.swingx.JTransparentTable;
import com.fjeld.swingx.table.ObserverTableModel;

import javax.swing.*;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: fjeld
 * Date: 11/12/2011
 * Time: 21:15
 *
 * Lists the detected servers for as long as the management server is up.
 */
public class ServerFarmView extends JTransparentPanel
{
    private ObserverTableModel tableModel;

    public ServerFarmView()
    {
        JLabel header = LabelFactory.createHeaderLabel("Servers detected:");

        JTransparentPanel p1 = new JTransparentPanel();
        JTransparentPanel p = new JTransparentPanel();
        p.add(header, BorderLayout.WEST);
        p1.add(p, BorderLayout.NORTH);

        tableModel = new HeartbeatTableModel();
        JTable table = new JTransparentTable(tableModel);
        table.setDefaultRenderer(Object.class, new HeartbeatCellRenderer());
        JTransparentScrollPane scrollPane = new JTransparentScrollPane(table);
        p1.add(scrollPane, BorderLayout.SOUTH);

        add(p1, BorderLayout.NORTH);
    }

    public void addListener(HeartbeatListener hbl)
    {
        tableModel.setData(hbl.getServerList());
    }
}

